const Router = require('koa-router')
const { verifyToken } = require('@/utils/jwt')
const shareValidate = require('@/middlewares/validateMiddlewares/shareValidate')
const shareController = require('@/controller/shareController')
const { verifyAuth } = require('@/middlewares/authMiddlewares/verifyAuth')
const sourceLog = require('@/middlewares/logMiddlewares/sourceLog')

const router = new Router()

/**
 * 获取分享列表
 */
router.get(
  '/list',
  verifyToken(),
  verifyAuth(['admin.storage.list']),
  shareValidate.listShareValidate,
  shareController.listShare
)

/**
 * 获取分享列表
 */
router.get(
  '/id/list',
  // verifyToken(),
  // verifyAuth(['admin.storage.list']),
  shareController.listLinkShareById
)

/**
 * 获取分享给我的内部协作分享
 */

router.get(
  '/shareToMe/list',
  verifyToken(),
  // verifyAuth(['admin.storage.list']),
  shareValidate.listUserInnerShareValidate,
  shareController.listUserInnerShare
)

/**
 * 前台用户获取分享列表
 */
router.get(
  '/user/list',
  verifyToken(),
  verifyAuth(['source.shareLink', 'source.share']),
  shareValidate.listUserShareValidate,
  shareController.listUserShare
)

/**
 * 创建分享
 */
router.post(
  '/create',
  verifyToken(),
  verifyAuth(['source.shareLink', 'source.share']),
  shareValidate.createShareValidate,
  shareController.createShare
)

/**
 * 更新分享
 */
router.put(
  '/update',
  verifyToken(),
  shareValidate.updateShareValidate,
  sourceLog.updateSourceLog,
  shareController.updateShare
)

/**
 * 取消分享
 */
router.put(
  '/cancel',
  verifyToken(),
  shareValidate.cancelShareValidate,
  sourceLog.updateSourceLog,
  shareController.cancelShare
)

/**
 * 删除分享
 */
router.delete(
  '/delete',
  verifyToken(),
  verifyAuth(['admin.storage.edit']),
  shareValidate.delSharesValidate,
  shareController.delShares
)

/**
 * 外链分享浏览数增加接口
 */
router.put(
  '/numView/add',
  shareValidate.shareNumViewAddValidate,
  shareController.shareNumViewAdd
)

/**
 * 外链分享下载数增加接口
 */
router.put(
  '/numDownload/add',
  shareValidate.shareNumViewAddValidate,
  shareController.shareNumDownloadAdd
)

module.exports = router
